package kr.or.kead.ui.meun;

import java.awt.Container;
import java.awt.Dimension;
import java.util.StringTokenizer;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

import kr.or.kead.domain.Auth;
import kr.or.kead.service.DaoInfoStudent;
import kr.or.kead.service.DaoTable;
import kr.or.kead.ui.list.AbsTableList;
import kr.or.kead.ui.list.StdTableList;


public class MenuMgn extends JMenuBar{
	private JMenu stdMgn; 		//학생 관리
	private AbsTableList listView;
	private DaoTable dao;
	private JMenu departmgn;
	private JFrame frame;
	private JMenu professorMgn;
	private JMenu basicsMgn;
	private JMenu courseMgn;
	private JMenu reqCourseMgn;
	private static Auth auth;
	
	

	public MenuMgn(JFrame frame) {
		super();
		this.frame = frame;
		dao = new DaoInfoStudent();
		init();
	}
	
	public void enableMenu() {
		StringTokenizer st = new StringTokenizer(auth.getEmail(), "@");
		basicsMgn.setText(st.nextToken());
		if (auth!=null){
			int level = auth.getLevel();
			if (level==1){		//학생
				courseMgn.setVisible(false);
				departmgn.setVisible(false);
				professorMgn.setVisible(false);
			}else if (level==2){// 교수
				stdMgn.setVisible(false);
				departmgn.setVisible(false);
			}
			else{
				listView = new StdTableList((int)frame.getSize().getHeight());
				Container contentPane = frame.getContentPane();
				contentPane.add(listView);
			}
		}
	}

	private void init() {
		frame.setSize(new Dimension(1300,300));
		basicsMgn = new BasicsMgn(frame);
		add(basicsMgn);
		
		stdMgn = new StdMenu(frame, (int)frame.getSize().getHeight());
		add(stdMgn);
		
		departmgn = new DepartMenu(frame, (int)frame.getSize().getHeight());
		add(departmgn);
		
		professorMgn = new ProfessorMenu(frame, (int)frame.getSize().getHeight());
		add(professorMgn);
		
		courseMgn = new CourseMenu(frame, (int)frame.getSize().getHeight());
		add(courseMgn);
		
		reqCourseMgn = new RequestMenu(frame, (int)frame.getSize().getHeight());
		add(reqCourseMgn);
		
	}
	public static Auth getAuth() {
		return auth;
	}

	public void setAuth(Auth auth) {
		this.auth = auth;
	}
	
}
